package com.songlanyun.modules.donation.controller.api;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.donation.entity.DonationEntity;
import com.songlanyun.modules.donation.model.DonationEntityDTO;
import com.songlanyun.modules.donation.service.DonationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;



/**
 * 公益捐款
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2022-07-21 11:32:51
 */
@RestController
@RequestMapping("api/donation")
public class ApiDonationController  extends AbstractApiController {
    @Autowired
    private DonationService donationService;

    /**
     * 列表
     */
    @GetMapping("/page")
    //@RequiresPermissions("donation:donation:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("user_id",getUserId(true));
        PageUtils page = donationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("donation:donation:info")
    public R info(@PathVariable("id") Long id){
        DonationEntity donation = donationService.loadById(id,false);
        return R.ok().put("data", donation);
    }

    /**
     * 申请
     */
    @PostMapping("/apply")
    //@RequiresPermissions("donation:donation:save")
    public R apply(@RequestBody DonationEntityDTO dto){
        dto.setUserId(getUserId(true));
		donationService.apply(dto);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("donation:donation:delete")
    public R delete(@PathVariable("id") Long id){
		donationService.removeMy(id,getUserId(true));
        return R.ok();
    }

}
